<template>
  <div class="cinema">
    <top-bar>
      <template #left>
        <div @click="toCity">
          <current-city />
          <i class="iconfont icon-xia"></i>
        </div>
      </template>
      <template #center>
        <span>影院</span>
      </template>
      <template #right>
        <div @click="toSearch">
          <i class="iconfont icon-fangdajing"></i>
        </div>
      </template>
    </top-bar>
    <van-dropdown-menu active-color="#FF5F16">
      <van-dropdown-item v-model="value1" :options="option1" />
      <van-dropdown-item v-model="value2" :options="option2" />
      <van-dropdown-item v-model="value3" :options="option3" />
    </van-dropdown-menu>
    <b-scroll
      class="wrapper"
      ref="wrapper"
      :data="moviesList"
      :pullDown="true"
      @pullDown="pullDown"
      :scrollEnd="true"
      @scrollEnd="scrollEnd"
    >
      <ul class="cinema-list">
        <li v-for="(item, index) in moviesList" :key="item.cinemaId">
          <div class="left">
            <span class="name">{{ item.name }}</span>
            <span class="address">{{ item.address }}</span>
          </div>
          <div class="right">
            <span class="price">¥ {{ item.lowPrice | priceSplice }} 起</span>
            <p>{{ index }}</p>
          </div>
        </li>
      </ul>
    </b-scroll>
  </div>
</template>

<script>
import TopBar from "@/components/TopBar";
import BScroll from "@/components/BScroll";
import CurrentCity from "@/components/CurrentCity";
import { getCinemaAPI } from "@/network/api";

export default {
  data() {
    return {
      moviesList: [],
      cityId: localStorage.getItem("cityId"),
      value1: 0,
      value2: "a",
      value3: "b",
      option1: [
        { text: "全城", value: 0 },
        { text: "西城区", value: 1 },
        { text: "东城区", value: 2 },
        { text: "海定区", value: 3 },
        { text: "朝阳区", value: 4 },
        { text: "丰台区", value: 5 },
        { text: "大兴区", value: 6 },
      ],
      option2: [
        { text: "APP订票", value: "a" },
        { text: "前台兑换", value: "b" },
      ],
      option3: [
        { text: "最近去过", value: "a" },
        { text: "离我最近", value: "b" },
      ],
    };
  },
  filters: {
    priceSplice(val) {
      let str = val + "";
      return str.slice(0, -2) + "." + str.slice(-2);
    },
  },
  components: {
    TopBar,
    BScroll,
    CurrentCity,
  },
  methods: {
    pullDown() {
      console.log("下拉了");
    },
    scrollEnd() {
      console.log("上");
    },
    // backClick() {
    //   // 通过坐标跳转
    //   this.$refs.wrapper.scrollTo(0, 0, 1000);
    // },
    toCity() {
      this.$router.push("/city");
    },
    toSearch() {
      this.$router.push("/search");
    },
  },
  mounted() {
    this.cityId = localStorage.getItem("cityId") || 110100;
    getCinemaAPI({
      cityId: this.cityId,
      ticketFlag: 1,
      k: 2783633,
    }).then((res) => {
      this.moviesList = res.data.data.cinemas;
    });
  },
};
</script>

<style scoped  lang="less" >
.wrapper {
  height: calc(100vh - 44px - 49px);
}
.cinema-list {
  background-color: #fff;
  li {
    padding: 10px 20px;
    border-bottom: 1px solid rgb(245, 241, 241);
    display: flex;
    justify-content: space-between;
    .left {
      width: 220px;
      display: flex;
      flex-direction: column;
      span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .address {
        color: #797d82;
        font-size: 12px;
      }
    }
    .right {
      width: 70px;
      text-align: right;
      .price {
        color: #ff5f16;
      }
    }
  }
}
</style>